package com.myres.struts2.action;

import java.util.List;
import java.util.Set;

import org.springframework.context.ApplicationContext;

import com.myres.biz.ShopBiz;
import com.myres.dao.ProductDao;
import com.myres.dao.ShopDao;
import com.myres.model.Product;
import com.myres.model.Shop;
import com.myres.model.User;
import com.myres.service.ShopService;
import com.myres.spring.SpringUtils;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class GetMyProductAction extends ActionSupport {
	private User user;
	private Set<Product> products;
	private ShopService getShopListService;
	private ProductDao productDao;
	public ProductDao getProductDao() {
		return productDao;
	}
	public void setProductDao(ProductDao productDao) {
		this.productDao = productDao;
	}
	public GetMyProductAction(){
		super();
		System.out.println("constructor of GetMyProductAction");
	}
	public ShopService getGetShopListService() {
		return getShopListService;
	}
	public void setGetShopListService(ShopService getShopListService) {
		this.getShopListService = getShopListService;
	}
	public Set<Product> getProducts() {
		return products;
	}
	public void setProducts(Set<Product> products) {
		this.products = products;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	/**
	 * @return
	 */
	public String execute() {
		// TODO Auto-generated method stub
		user = (User) ActionContext.getContext().getSession().get("user");
		Set<Shop> shops =getShopListService.getMyShop(user.getId());
		java.util.Iterator<Shop> iter=shops.iterator();
		Shop shop=null;
		while(iter.hasNext()){
			shop= iter.next();
			break;
		}
		if(shop == null){
			System.out.println("no shop ...");
			return "no_product";
		}
		products = shop.getProducts();
		
		if(products == null || products.size() == 0) {
			System.out.println("no product ...");
			return "no_product";
		}
		System.out.println("has product ...");
		return SUCCESS;
	}
}